package com.itany.book.service.impl;

import com.itany.mapper.PermissionMapper;
import com.itany.mapper.RoleMapper;
import com.itany.pojo.Role;
import com.itany.service.IndexService;
import com.itany.vo.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * Author：sl
 * Date：2019-09-28 下午1:52
 * Description：<描述>
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    RoleMapper roleMapper;

    @Autowired
    PermissionMapper permissionMapper;


    /**
     * 根据当前登录用户，查询当前用户的所有角色
     * 根据角色查询所有权限模块（一级菜单）去重
     * 根据模块，查询当前用户所有的权限，去重
     *
     * @return
     */
    public HashSet<Menu> showMenu(int userId) {

        HashSet<Menu> hashSet=new HashSet<Menu>();
        List<Role> roles = roleMapper.selectAllByLoginUserId(userId);

        List<String> ids = new ArrayList<String>();
        if (roles.size() != 0) {
            for (Role role : roles) {
                ids.add(role.getId()+"");
            }
            hashSet = permissionMapper.selectModuleByRoleId(String.join(",",ids));

        }




        return hashSet;
    }
}
